package cn.tedu.basic;
/**
 * 关闭工具类
 *
 */

import java.io.Closeable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class CloseableUtils {
    public static void close(ResultSet rs, PreparedStatement ps, Connection con){
        if(rs!=null) {//为了防止空指针异常
            try {
                rs.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally{//为了防止close时又异常
                rs=null;
            }
            if(ps!=null) {
                try {
                    ps.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                } finally {
                    ps = null;
                }
            }
            if(con!=null) {
                try {
                    con.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                } finally {
                    con = null;
                }
            }
        }
    }
}
